import pymysql
import xlrd

#链接数据库
def excu(sql,param):
    #通过四大参数链接数据库
    con=pymysql.connect(host="localhost",port=3306,user="root",passwd="123456",db="test")
    #通过链接创建控制台
    cursor=con.cursor()
    #准备SQL语句
    #sql="INSERT INTO baidu VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"
    #执行语句
    cursor.executemany(sql, param)
    #提交到数据库
    con.commit()
    #关闭资源
    cursor.close()
    con.close()

if __name__ == '__main__':
    wb = xlrd.open_workbook(r'5.baidu-员工的人员信息.xls')
    sheet = wb.sheet_by_index(0)
    data = []

    for row in range(1, sheet.nrows):
        data.append(sheet.row_values(row))

    sql='INSERT INTO user_info VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'

    for i in range(0,70):
        param=data[i*1000:(i+1)*1000]
        excu(sql,param)
        print(f"已上传{len(param)}条数据")
        param.clear()

    print("上传完成")
